// src/backtesting/time-utils.ts
import { KlineBar } from '../services/market-data.service';

/**
 * 将KlineBar枚举值转换为毫秒数
 * @param bar - K线周期枚举
 * @returns 对应的毫秒数
 */
export function getKlineBarMilliseconds(bar: KlineBar): number {
  const s = 1000;
  const m = 60 * s;
  const h = 60 * m;
  const d = 24 * h;
  switch (bar) {
    case KlineBar.MINUTE_1: return m;
    case KlineBar.MINUTE_3: return 3 * m;
    case KlineBar.MINUTE_5: return 5 * m;
    case KlineBar.MINUTE_15: return 15 * m;
    case KlineBar.MINUTE_30: return 30 * m;
    case KlineBar.HOUR_1: return h;
    case KlineBar.HOUR_2: return 2 * h;
    case KlineBar.HOUR_4: return 4 * h;
    case KlineBar.DAY_1: return d;
    default: return h; // 默认为1小时
  }
}
